package com.grantha.controllers;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import com.grantha.util.DB;


/**
 * Servlet implementation class ReservationListServelet
 */
@WebServlet("/ReservationListServelet")
public class ReservationListServelet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	Logger log = Logger.getLogger(this.getClass());
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ReservationListServelet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("application/json");
		PrintWriter out = response.getWriter();
		
		log.info("Servlet Stated");
		//coding start 
		
		String custno = request.getParameter("custno"); 
		String bookno = request.getParameter("bookno");
		
		
		log.info("custno="+custno);
		log.info("bookno="+bookno);
		
		
		
		try {
			
			DB.update("insert into books (custno, bookno) values (?, ?)", custno, bookno );
			out.print("success");
			log.info("success");
		} catch (Exception e) {
			out.print("error");
			log.error("Error");
		}
		
		//coding ends
		
		out.close();
		log.info("Servlet end");
	}
	

}
